package org.vectrics.common.view;

import org.apache.ecs.html.Input;
import org.vectrics.common.html.Cell;
import org.vectrics.common.html.Row;

public class HtmlFormCheckBoxRow extends HtmlFormRow {
	boolean readOnly = false;
	public HtmlFormCheckBoxRow(HtmlForm form, String paramName,
			boolean required, boolean readOnly) {
		super(form, paramName, required);
		this.readOnly = readOnly;
	}

	public void setValue(boolean checked) {
        if (this.readOnly) {
            if (checked) {
            	this.getValueDiv().addElement("True");
            } else {
            	this.getValueDiv().addElement("False");
            }
        } else {
            Input checkbox = makeCheckBox(this.getParamName(), checked);
            this.getValueDiv().addElement(checkbox);
        }
	}

	
	
	public Input makeCheckBox(String paramName, boolean checked) {
        Input checkBox = new Input();
        checkBox.setType(Input.checkbox);
        checkBox.setName(paramName);
        checkBox.setChecked(checked);

    	checkBox.setID(paramName);
    	this.getHtmlForm().setFocusElementIfNull(paramName);    	
        return(checkBox);
    }
	
}
